package com.orhon.smartcampus.modules.schoolaffairs.entity;


import com.orhon.smartcampus.modules.base.entity.Dictionary;
import com.orhon.smartcampus.modules.base.entity.Schools;
import com.orhon.smartcampus.modules.student.entity.Eclass;
import com.orhon.smartcampus.modules.systemctl.entity.OrgDepartments;
import com.orhon.smartcampus.modules.user.entity.Users;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Date;

@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "schoolAdministration_notice", schema = "smartcloud", catalog = "")
public class SchoolNotice {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;



    @Column(name = "title", nullable = true, length = 255)
    private String title;

    @Column(name="url" ,nullable  =true)
    private String url;

    @Column(name = "content", nullable = true)
    private String content;

    @Column(name = "created_by", nullable = true)
    private Integer createdBy;


    @Column(name = "created_at", nullable = true)
    private Date createdAt;

    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;

    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;

    //学校
    @ManyToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @JoinColumn(name = "school_id")
    @NotFound(action= NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    private Schools schoolsBySchool;

    //发布人
    @ManyToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    @NotFound(action= NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    private Users publisher;

    //部门
    @ManyToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @JoinColumn(name = "depart_id")
    @NotFound(action= NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    private OrgDepartments department;

    //班级
    @ManyToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @JoinColumn(name = "eclass_id")
    @NotFound(action= NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    private Eclass eclass;

    /**
     * 公告分类关联字典表
     */
    @ManyToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @JoinColumn(name = "type", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    @Where(clause = "ISNULL(deleted_at)")
    private Dictionary type;
}
